<?php 
## include required files
/*******************************/
require_once '../model/seo.php';
require_once '../model/moduleuser.php';
## Paginaton class
require_once ("../includes/classes/pagination_class.php");
/*******************************/

## Create Objects
/*******************************/
$seoObj = new Model_SEO();
$moduleObj=new Model_ModuleUser();
/*******************************/

if($_GET['q']=='seo')
{
	$moduelArray=$moduleObj->getModuleHelpText(20);
	$smarty->assign('moduelArray', $moduelArray);
}


/*******************************/
##Fetch all cms pages from database
/******************************/
## Get search parameters in variables - 
if($_POST['search'] != '' && $_POST['search'] != 'Search') {
	$searchindex = return_post_value($_POST['search']);
} else if($_GET['search'] != '') {
	$searchindex = return_post_value($_GET['search']);
} else {
	$searchindex = '';
}
// Assign search variable to show in search textbox
$smarty->assign('search', $searchindex);

if($_GET['col1'] != '') 
{
	$col1 = base64_decode($_GET['col1']);
}  

##  --------- Pagination part first start --------------##
	if( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] != "" ) {
		$pageNum = $_GET[ 'page' ];
	} else {
		$pageNum = 1;
	} 
	$rowsPerPage = ROW_PER_PAGE;
	if($_GET['col1'] != '') 
	{
		$pageName = "home.php?q=seo&col1=".$_GET['col1'].""; ;
	} 
	else 
	{
		$pageName = "home.php?q=seo"; 
	}

	
	## Count all the records
	$cmsArray = $seoObj->getAllSeos($searchindex,$col1);
	$total_rows = count($cmsArray);
	$offset	= ($pageNum - 1) * $rowsPerPage;
	$smarty->assign('page', $pageNum);
##  --------- Pagination part first end --------------##


##  --------- Pagination part second start --------------##
	$newid = $pageNum * $rowsPerPage - $rowsPerPage + 1;
	$smarty->assign('newid', $newid);
	$seoArray = $seoObj->getAllSeos($searchindex,$col1,$rowsPerPage,$offset);
	//echo "<pre>"; print_r($seoArray);exit;
	$smarty->assign('seoArray', $seoArray);
	
	$other_id = '';
	
	if($searchindex != '') {
		$other_id = "search=".$searchindex;
	} 
	
	if($order_field != '') {
		if($other_id == '') {
			$other_id = "order_field=".$order_field;
		} else {
			$other_id.= "&order_field=".$order_field;
		}
	}
	
	if($order_by != '') {
		if($other_id == '') {
			$other_id = "order_by=".$order_by;
		} else {
			$other_id.= "&order_by=".$order_by;
		}
	}
	
	if($total_rows > ROW_PER_PAGE) {
		$pg = new pagination();					// CREATING OBJECT OF THE PAGINATION CLASS
		$pgnation = $pg->pagination_admin( $total_rows , $rowsPerPage , $pageNum , $pageName , $other_id, $class);	
		$smarty-> assign("pagination",$pgnation);
	}
##  --------- Pagination part second end --------------##	

## Assign session message to smarty variable and unset session variable
if($_SESSION['msg'] != '') {
	$smarty->assign('msg', $_SESSION['msg']);	
	unset($_SESSION['msg']);
}

## Set active class variable for left menu  (main menu and sub menu)
$smarty->assign('activeclass', 'seo');
$smarty->assign('mainmenu', '6');

## Unset all the objects created which are on this page
unset($seoObj);
unset($moduleObj);

$smarty->display(TEMPLATEDIR_ADMIN. 'seo/seo.tpl');
unset($smarty);
?>